package tt.dz.egobus.api.impl;

import com.alibaba.dubbo.config.annotation.Service;
import org.apache.commons.lang3.StringUtils;
import tt.dz.egobus.api.ResponseBack;
import tt.dz.egobus.api.common.AbstractFacadeFactoryService;
import tt.dz.egobus.api.managerservice.relative.DriverRelativeApiService;
import tt.dz.egobus.api.managerservice.relative.DriverRelativeView;
import tt.dz.egobus.servicemanager.entities.DriverRegisterBusRelative;
import tt.dz.egobus.servicemanager.facade.interator.FacadeFactory;
import tt.dz.egobus.servicemanager.facade.interator.FacadeFactoryLoggerInterceptorHolder;
import tt.dz.egobus.servicemanager.service.DriverRegisterBusRelativeService;
import tt.dz.egobus.servicemanager.util.PojoConvertVoUtils;

import java.util.List;

import static tt.dz.egobus.bean.I18NCodeEnum.RPC_PARAM_ILLEGAL_ERROR;

/**
 * @author Anson
 * @date 17-8-25
 * @name 司机绑定的状态API服务实现类
 * @since 1.0.6
 */
@Service(version = "1.0.6", interfaceClass = DriverRelativeApiService.class)
public class DriverRelativeApiServiceImpl  extends AbstractFacadeFactoryService implements DriverRelativeApiService {

    private static final String DRIVER_REGISTER_SERVICE_NAME = "grabDriverRegisterBusRelativeServiceImpl";

    @Override
    protected FacadeFactory getFacadeFactory() {
        return FacadeFactoryLoggerInterceptorHolder.LOGGER_FACADE;
    }

    @Override
    public ResponseBack<DriverRelativeView> getOnlineDriverRelativeInfo(String driverId) {
        if (StringUtils.isEmpty(driverId)) {
            return ResponseBack.error(this.get(RPC_PARAM_ILLEGAL_ERROR));
        }
        DriverRegisterBusRelativeService service = this.getDriverBusRegisterService();
        List<DriverRegisterBusRelative> driverRegisterBusRelatives = service.queryValidateCarDriverBind(driverId);
        if(driverRegisterBusRelatives.size()==0){
            return  ResponseBack.success(null);
        }
        DriverRegisterBusRelative registerBusRelative = driverRegisterBusRelatives.get(0);
        DriverRelativeView view = PojoConvertVoUtils.driverRelativeConvertRelativeView(registerBusRelative);
        return ResponseBack.success(view);
    }


    DriverRegisterBusRelativeService getDriverBusRegisterService(){
        return this.getService(DRIVER_REGISTER_SERVICE_NAME, DriverRegisterBusRelativeService.class);
    }
}
